/**
 * initialize your data structure here.
 */
var MedianFinder = function () {
    this.array = []
};

/** 
 * @param {number} num
 * @return {void}
 */
MedianFinder.prototype.addNum = function (num) {
    this.array.push(num)
    this.array.sort((a, b) => a - b)
};

/**
 * @return {number}
 */
MedianFinder.prototype.findMedian = function () {
    let len = this.array.length
    let flag
    if (len % 2 === 0) {
        flag = len / 2
        return (this.array[flag] + this.array[flag - 1]) / 2
    } else {
        flag = Math.floor(len / 2)
        return this.array[flag]
    }
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * var obj = new MedianFinder()
 * obj.addNum(num)
 * var param_2 = obj.findMedian()
 */